Ccay.Module.define("Ccay.example.ui.igrid.menuFunction",function(page,$S){
	page.ready = function(){
		
		var gridOption1 = {
			height: 300,
			editMode: true,
			contextMenu:true,
			menuOp:{
        		 menus:[{type: 'del'}, {type: 'undo'}, {type: "copy"}]
        	},
	        columns: [
				 {columnType: "select", multi: true},
 			     {field: 'name', width:200, header: "name", menuable: true, rule: {required: true}},
 				 {field: 'description', width:200, header: "description"},
 				 {field: 'id', width:100, header: "id", editable: false}
	        ],
		    ajax: {
		    	url: 'services/ccay/demo/grid/list/page/${pageSize}/${curPage}/${orderBy}'
		    },
		    operation: {
		    	search: {
		    		btn: '#btnMenuSearch',
					panel: '#menuForm'
		    	},
		    	del: {
		    		btn: '#btnMenuDel',
		    		undoBtn: '#btnMenuUndoDel'
		    	},
		    	insert: {
		    		btn: '#btnMenuAdd',
		    		copy: true,
		    		clear: ['id']
		    	},
		    	save: {
		    		btn: '#btnMenuSave',
		    		ajax: {
		    			url: "services/ccay/demo/grid/batch"
		    		}
		    	}
		    }
	    };
	    
	    var gridOption2 = {
			height: 300,
			editMode: true,
			contextMenu:true,
			menuOp:{
        		 menus:[{
        		 	text: '向后复制', 
        		 	click: function (cell, menu) {
        		 		$S("#iStudent2").manager().copyCellData(cell);
        		 	}
        		 }, {
        		 	text: '向下复制', 
        		 	click: function (cell, menu) {
        		 		$S("#iStudent2").manager().copyCellData(cell, true);
        		 	}
        		 }]
        	},
	        columns: [
				 {columnType: "select", multi: true},
 			     {field: 'name', width:200, header: "name", menuable: true, rule: {required: true}},
 				 {field: 'description', width:200, header: "description"},
 				 {field: 'id', width:100, header: "id", editable: false}
	        ],
		    ajax: {
		    	url: 'services/ccay/demo/grid/list/page/${pageSize}/${curPage}/${orderBy}'
		    },
		    operation: {
		    	search: {
		    		btn: '#btnMenusSearch',
					panel: '#menusForm'
		    	},
		    	del: {
		    		btn: '#btnMenusDel',
		    		undoBtn: '#btnMenusUndoDel'
		    	},
		    	insert: {
		    		btn: '#btnMenusAdd',
		    		copy: true,
		    		clear: ['id']
		    	},
		    	save: {
		    		btn: '#btnMenusSave',
		    		ajax: {
		    			url: "services/ccay/demo/grid/batch"
		    		}
		    	}
		    }
	    };
		
		$S("#menuFunctionDemo").ccayTab();
		
		//点击tab头后，才加载数据，只第一次生效
		$S("li[tabid='tab2']").one("click", function () {
			$S("#iStudent1").igrid(gridOption1);
		});
		
		$S("li[tabid='tab3']").one("click", function () {
			$S("#iStudent2").igrid(gridOption2);
		});
	};
	
	page.operateTest = function (value) {
		alert(Ccay.DataHelper.toJsonStr(value));
	};
	
	page.openDemo = function(tabId){
		$S("#menuFunctionDemo").getCcayTabManager().selectItem(tabId);
		$S("li[tabid='" + tabId + "']").click();
	};
	
});